#!/bin/sh
#
# This file is part of OpenMediaVault.
#
# @license   https://www.gnu.org/licenses/gpl.html GPL Version 3
# @author    Volker Theile <volker.theile@openmediavault.org>
# @copyright Copyright (c) 2009-2025 Volker Theile
#
# OpenMediaVault is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# OpenMediaVault is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenMediaVault. If not, see <https://www.gnu.org/licenses/>.

. /usr/share/debconf/confmodule

set -e

logger -t finish-install "Update system configuration"

db_progress START 0 2 openmediavault-installer/finish-install/progress/update_sys_conf

# Regenerate SSH key for user 'root'. It was created during the build
# process of the ISO image.
logger -t finish-install "Update system configuration - SSH [1/3]"
db_progress INFO openmediavault-installer/finish-install/progress/info/regen_ssh_keys
in-target rm -f /root/.ssh/id_rsa
in-target rm -f /root/.ssh/id_rsa.pub
in-target ssh-keygen -t rsa -b 4096 -f /root/.ssh/id_rsa -N ''

# Deploy imported network settings as systemd-networkd configuration.
logger -t finish-install "Update system configuration - systemd-networkd [2/3]"
db_progress STEP 1
db_progress INFO openmediavault-installer/finish-install/progress/info/deploy_systemd_networkd
in-target omv-salt deploy run systemd-networkd || true

# Update the APT settings. Wipe duplicate package repositories.
logger -t finish-install "Update system configuration - APT [3/3]"
db_progress STEP 1
db_progress INFO openmediavault-installer/finish-install/progress/info/deploy_apt
in-target omv-salt deploy run apt || true

db_progress STOP

exit 0
